{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5]\n",
      "[1 2 3 4 5]\n",
      "[1 2 3 4 5]\n",
      "[[1, 2, 3], [4, 5, 6]]\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[0 1 2 3 4]\n",
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "[1 3 5 7 9]\n"
     ]
    }
   ],
   "source": [
    "# 创建numpy对象\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "# 通过列表来创建\n",
    "ls = [1,2,3,4,5]\n",
    "print(ls)\n",
    "a = np.array(ls)\n",
    "print(a)\n",
    "\n",
    "tup = (1,2,3,4,5)\n",
    "a = np.array(tup)\n",
    "print(a)\n",
    "\n",
    "ls = [[1,2,3],[4,5,6]]\n",
    "print(ls)\n",
    "a = np.array(ls)\n",
    "print(a)\n",
    "\n",
    "a = np.array(range(5))\n",
    "print(a)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "[1 3 5 7 9]\n",
      "[ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]\n",
      "[ 0.          0.20408163  0.40816327  0.6122449   0.81632653  1.02040816\n",
      "  1.2244898   1.42857143  1.63265306  1.83673469  2.04081633  2.24489796\n",
      "  2.44897959  2.65306122  2.85714286  3.06122449  3.26530612  3.46938776\n",
      "  3.67346939  3.87755102  4.08163265  4.28571429  4.48979592  4.69387755\n",
      "  4.89795918  5.10204082  5.30612245  5.51020408  5.71428571  5.91836735\n",
      "  6.12244898  6.32653061  6.53061224  6.73469388  6.93877551  7.14285714\n",
      "  7.34693878  7.55102041  7.75510204  7.95918367  8.16326531  8.36734694\n",
      "  8.57142857  8.7755102   8.97959184  9.18367347  9.3877551   9.59183673\n",
      "  9.79591837 10.        ]\n",
      "[ 0.          0.20408163  0.40816327  0.6122449   0.81632653  1.02040816\n",
      "  1.2244898   1.42857143  1.63265306  1.83673469  2.04081633  2.24489796\n",
      "  2.44897959  2.65306122  2.85714286  3.06122449  3.26530612  3.46938776\n",
      "  3.67346939  3.87755102  4.08163265  4.28571429  4.48979592  4.69387755\n",
      "  4.89795918  5.10204082  5.30612245  5.51020408  5.71428571  5.91836735\n",
      "  6.12244898  6.32653061  6.53061224  6.73469388  6.93877551  7.14285714\n",
      "  7.34693878  7.55102041  7.75510204  7.95918367  8.16326531  8.36734694\n",
      "  8.57142857  8.7755102   8.97959184  9.18367347  9.3877551   9.59183673\n",
      "  9.79591837 10.        ]\n",
      "[0.  0.2 0.4 0.6 0.8 1.  1.2 1.4 1.6 1.8 2.  2.2 2.4 2.6 2.8 3.  3.2 3.4\n",
      " 3.6 3.8 4.  4.2 4.4 4.6 4.8 5.  5.2 5.4 5.6 5.8 6.  6.2 6.4 6.6 6.8 7.\n",
      " 7.2 7.4 7.6 7.8 8.  8.2 8.4 8.6 8.8 9.  9.2 9.4 9.6 9.8]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(10)\n",
    "print(a)\n",
    "a = np.arange(1,10,2)\n",
    "print(a)\n",
    "\n",
    "a = np.linspace(0,10,11)\n",
    "print(a)\n",
    "a = np.linspace(0,10)\n",
    "print(a)\n",
    "a = np.linspace(0,10)\n",
    "print(a)\n",
    "a = np.linspace(0,10,endpoint=False)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 0. 0. 0. 0.]\n",
      "[[0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]]\n",
      "[[1. 1. 1. 1. 1.]\n",
      " [1. 1. 1. 1. 1.]\n",
      " [1. 1. 1. 1. 1.]\n",
      " [1. 1. 1. 1. 1.]\n",
      " [1. 1. 1. 1. 1.]]\n"
     ]
    }
   ],
   "source": [
    "a = np.zeros(5)\n",
    "print(a)\n",
    "\n",
    "a = np.zeros((5,5))\n",
    "print(a)\n",
    "\n",
    "a = np.ones((5,5))\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(10)\n",
    "print(a)\n",
    "\n",
    "print(a[9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n",
      "6\n",
      "21\n",
      "[5 7 9]\n",
      "[10 14 18]\n",
      "6\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# 列表+ 连起来\n",
    "ls1 = [1,2,3]\n",
    "ls2 = [4,5,6]\n",
    "ls3 = ls1+ls2\n",
    "print(ls3)\n",
    "print(max(ls3))\n",
    "print(sum(ls3))\n",
    "\n",
    "# np数组 + \n",
    "a = np.array([1,2,3])\n",
    "b = np.array([4,5,6])\n",
    "c = a + b\n",
    "print(c)\n",
    "\n",
    "d = c*2\n",
    "print(d)\n",
    "\n",
    "print(a.sum())\n",
    "print(a.max())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8]\n",
      "[[0 1 2]\n",
      " [3 4 5]\n",
      " [6 7 8]]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(9)\n",
    "print(a)\n",
    "\n",
    "# b = a.reshape(3,3)\n",
    "# print(b)\n",
    "\n",
    "a.shape = 3,3\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
